package com.hb.znpt.activity;

import android.content.DialogInterface;
import android.os.Bundle;

import androidx.appcompat.app.AlertDialog;
import androidx.lifecycle.Observer;

import com.hb.znpt.BR;
import com.hb.znpt.R;
import com.hb.znpt.bean.CropsBean;
import com.hb.znpt.databinding.ActivityLandAddBinding;
import com.hb.znpt.viewmodel.LandAddViewModel;
import com.unitlib.base.base.BaseActivity;

import java.util.List;

public class LandAddActivity extends BaseActivity<ActivityLandAddBinding, LandAddViewModel> {

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.activity_land_add;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        viewModel.setDeptid(getIntent().getStringExtra("deptid"));
    }

    @Override
    public void initViewObservable() {
        viewModel.cropClick.observe(this, new Observer<List<CropsBean>>() {
            @Override
            public void onChanged(List<CropsBean> beans) {
                String[] strings = new String[beans.size()];
                for (int i = 0; i < beans.size(); i++) {
                    strings[i] = beans.get(i).getZwmc();
                }
                AlertDialog.Builder listDialog = new AlertDialog.Builder(LandAddActivity.this);
                listDialog.setItems(strings, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        binding.tvName.setText(beans.get(which).getZwmc());
                    }
                }).show();
            }
        });
    }
}
